/**
 * Created by KingKong on 2017/8/9.
 */
import {AbstractControl, ValidatorFn} from '@angular/forms';

/**
 * 自定义验证规则：最大值，用于输入数字类型
 * */
export function customizeMaxValueValidator(max: number, key: string): ValidatorFn {
  return (control: AbstractControl): { [key: string]: any } => {
    let ret = parseInt(control.value, 10);
    ret = isNaN(ret) ? 0 : ret;
    return ret <= max ? null : {[key]: true};
  };
}
